//
//  EvaluateViewController.m
//  rrqs
//
//  Created by 朱耀春 on 2019/5/3.
//

#import "EvaluateChildViewController.h"
#import "EvaluateTableViewCell.h"
#import "EvaluateModel.h"

@interface EvaluateChildViewController ()
<UITableViewDelegate,
UITableViewDataSource>
{
    NSDictionary * dataDic;
}

@property (weak, nonatomic) IBOutlet UITableView *mainTableView;

@property (nonatomic, copy)  NSMutableArray * dataArr;

@end

@implementation EvaluateChildViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    //tableView自动适配
    self.mainTableView.rowHeight = UITableViewAutomaticDimension;
    self.mainTableView.estimatedRowHeight = 22;
    [self queryData];
}

-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.dataArr.count > 0 ) {
        return self.dataArr.count;
    }
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

#pragma mark 设置cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    EvaluateTableViewCell * cell = (EvaluateTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"EvaluateTableViewCell"];
    if (self.dataArr.count > 0 ) {
        cell.model = self.dataArr[indexPath.row];
    }
    //取消cell点击时显示的状态
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
    return cell;
}
#pragma mark 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)queryData {
    
    NSDictionary* arg = @{@"ince":@"get_evaluate",
                          @"eval_type":_type,
                    @"emp_id":self.Identity.userInfo.userID};
    NSLog(@"参数： %@",arg);
    __weak typeof(self) weakSelf = self;
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        [WMHelper outPutJsonString:data];
        NSInteger ret = [[data objectForKey:@"ret"]integerValue];
        if(ret == 200){
            [WMHelper outPutJsonString:data];
            weakSelf.dataArr = [EvaluateModel mj_objectArrayWithKeyValuesArray:data[@"data"][@"list"]];
            dataDic = data;
            if (self.numBlock) {
                weakSelf.numBlock(data[@"data"][@"num"]);
            }
            [weakSelf.mainTableView reloadData];
            
        }else{
            [self alertHUD:[data objectForKey:@"fail"]];
        }
        
    } failure:^(NSError *error) {
        [self alertHUD:@"网络异常"];
    }];
}



@end
